package mylab.usm.oauth2.client.controller;

import com.fujieid.jap.core.JapUserService;
import com.fujieid.jap.core.config.AuthenticateConfig;
import com.fujieid.jap.core.config.JapConfig;
import com.fujieid.jap.oauth2.OAuthConfig;
import com.fujieid.jap.oauth2.Oauth2Strategy;
import jakarta.annotation.Resource;
import me.zhyd.oauth.utils.UuidUtils;
import mylab.usm.oauth2.client.config.AuthProperties;

public abstract class BaseOAuth2Controller extends BaseAuthController<Oauth2Strategy> {

    @Resource(name = "oauth2")
    protected JapUserService japUserService;

    @Override
    protected JapUserService getUserService() {
        return japUserService;
    }

    @Override
    protected Oauth2Strategy getJapStrategy(JapUserService japUserService, JapConfig japConfig) {
        return new Oauth2Strategy(japUserService, japConfig);
    }

    @Override
    protected AuthenticateConfig getAuthenticateConfig(AuthProperties.Platform platform) {
        return new OAuthConfig()
                .setPlatform(platform.getPlatformId())
                .setState(UuidUtils.getUUID())
                .setClientId(platform.getClientId())
                .setClientSecret(platform.getClientSecret())
                .setCallbackUrl(platform.getCallbackUrl())
                .setAuthorizationUrl(platform.getCallbackUrl())
                .setTokenUrl(platform.getTokenUrl())
                .setUserinfoUrl(platform.getUserinfoUrl())
                .setScopes(platform.getScopes());
    }

}
